package com.fir.my.batis.plus.controller;

import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.fir.my.batis.plus.entity.SysDept;
import com.fir.my.batis.plus.entity.SysUser;
import com.fir.my.batis.plus.service.ISysDeptService;
import com.fir.my.batis.plus.service.ISysUserService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


/**
 * @author fir
 * @date 2024/5/24 9:29
 */

@RestController
@RequestMapping("/all")
public class ALlController {


    /**
     * 部门表 服务类
     */
    @Resource
    private ISysDeptService iSysDeptService;


    /**
     * 用户信息表 服务类
     */
    @Resource
    private ISysUserService iSysUserService;


    @DSTransactional
    @PostMapping("/up/up")
    public Boolean upUp(SysUser sysUser){
        boolean key = iSysUserService.updateById(sysUser);

        SysDept sysDept = new SysDept();
        sysDept.setDeptName("测试部门");
        boolean keySysDept = iSysDeptService.saveSd(sysDept);

        if(true){
            throw new RuntimeException();
        }

        return true;
    }


    @Transactional
    @PostMapping("/up/up/2")
    public Boolean upUp2(SysUser sysUser){
        boolean key = iSysUserService.updateById(sysUser);

        SysDept sysDept = new SysDept();
        sysDept.setDeptName("测试部门");
        boolean keySysDept = iSysDeptService.saveSd(sysDept);

        if(true){
            throw new RuntimeException();
        }

        return true;
    }


    @DSTransactional
    @PostMapping("/up/up/3")
    public Boolean upUp3(SysUser sysUser){
        boolean key = iSysUserService.updateById(sysUser);

        SysDept sysDept = new SysDept();
        sysDept.setDeptName("测试部门");
        boolean keySysDept = iSysDeptService.saveSd(sysDept);

        return true;
    }
}
